/*
*    Qizx/open 3.0 beta
*
* This code is the open-source version of Qizx.
* Copyright (C) 2004-2009 Axyana Software -- All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License 
*  Version 1.1 (the "License"); you may not use this file except in 
*  compliance with the License. You may obtain a copy of the License at
*  http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
*  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
*  for the specific language governing rights and limitations under the
*  License.
*
* The Initial Developer of the Original Code is Xavier Franc - Axyana Software.
*
*/
using System;
using EvaluationException = System.Qizx.Api.EvaluationException;
using ItemType = System.Qizx.Api.ItemType;
using QizxException = System.Qizx.Api.QizxException;
using XMLPullStream = System.Qizx.Api.XMLPullStream;
using XMLPushStream = System.Qizx.Api.XMLPushStream;
using Comparison = System.Qizx.Util.Basic.Comparison;
using BaseValue = System.Qizx.XQuery.BaseValue;
using ComparisonContext = System.Qizx.XQuery.ComparisonContext;
using XQItem = System.Qizx.XQuery.XQItem;
using XQType = System.Qizx.XQuery.XQType;
using XQValue = System.Qizx.XQuery.XQValue;
namespace System.Qizx.XQuery.Impl
{
	
	
	/// <summary>	Special values (always empty).
	/// Used to represent type matching errors.
	/// </summary>
	public class ErrorValue:BaseValue
	{
		public override ItemType ValueType
		{
			get
			{
				return XQType.ATOM;
			}
			
		}
		public override XQItem Item
		{
			get
			{
				return null; // whatever: should not be called
			}
			
		}
		virtual public string Reason
		{
			get
			{
				return reason;
			}
			
		}
		public override System.Object Object
		{
			get
			{
				throw new QizxException("invalid value");
			}
			
		}
		// when used as error:
		private string reason;
		
		public ErrorValue(string reason)
		{
			this.reason = reason;
		}
		
		public override bool Next()
		{
			return false; // by essence
		}
		
		public override XQValue BornAgain()
		{
			return this;
		}
		
		public override bool IsNode
		{
            get {
                return false; // should not be called
            }
		}
		
		public override XQItem AsAtom()
		{
			return Item; // should not be called
		}
		
		public override int CompareTo(XQItem that, ComparisonContext context, int flags)
		{
			return Comparison.ERROR;
		}
		
		public override void  Export(XMLPushStream writer)
		{
			throw new EvaluationException("invalid export");
		}
		
		public override XMLPullStream ExportNode()
		{
			return null;
		}
	}
}